package com.zzyl.nursing.controller.member;

import com.github.pagehelper.PageInfo;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.MemberReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private MemberReservationService memberReservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        System.out.println("------" + userId);
        return R.ok(1);
    }

//    @GetMapping("/cancelled-count")
//    public Map<String, Object> getCancelledCount() {
//        long cancelledCount = memberReservationService.getCancelledCount();
//
//        Map<String, Object> response = new HashMap<>();
//        response.put("data", cancelledCount);
//        response.put("code", 200);
//        response.put("msg", "操作成功");
//
//        return response;
//    }
@PostMapping
public ResponseEntity<Map<String, Object>> createReservation(@RequestBody Reservation reservation) {
    boolean success = memberReservationService.createReservation(reservation);

    Map<String, Object> response = new HashMap<>();
    if (success) {
        response.put("code", 200);
        response.put("msg", "操作成功");
    } else {
        response.put("code", 500);
        response.put("msg", "操作失败");
    }

    return ResponseEntity.ok(response);
}
    @GetMapping("/page")
    public ResponseEntity<Map<String, Object>> getReservations(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) Integer status) {
        PageInfo<Reservation> pageInfo = memberReservationService.getReservations(pageNum, pageSize, status);

        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("msg", "操作成功");
        response.put("data", pageInfo);

        return ResponseEntity.ok(response);
    }
}